/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package model.Bill;

import entities.Test;
import java.util.ArrayList;
import javax.swing.event.TableModelListener;
import javax.swing.table.TableModel;

/**
 *
 * @author Dell
 */
public class TableModelTest implements TableModel{
     private ArrayList<Test> testList;
     private String header[];

    public void setHeader(String[] header) {
        this.header = header;
    }

    public String[] getHeader() {
        return header;
    }

    public TableModelTest(ArrayList<Test> testList) {
        this.testList=new ArrayList<Test>();
        this.testList = testList;
    }



    @Override
    public int getRowCount() {

      if (testList != null) {
            return testList.size();
        } else {
            return 0;
        }
    }

    @Override
    public int getColumnCount() {
        return header.length;
    }

    @Override
    public String getColumnName(int columnIndex) {
      return header[columnIndex];
    }

    @Override
    public Class<?> getColumnClass(int columnIndex) {
       if (columnIndex == 0) {
            return String.class;
        } else {
            return Float.class;
        }
    }

    @Override
    public boolean isCellEditable(int rowIndex, int columnIndex) {
        return false;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
    if(columnIndex==0){
        return testList.get(rowIndex).getTestName();
    }
 else if(columnIndex==1){
     return testList.get(rowIndex).getTestCost();
 }
    return null;
    }

    @Override
    public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
   //     throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void addTableModelListener(TableModelListener l) {
  //      throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void removeTableModelListener(TableModelListener l) {
     //   throw new UnsupportedOperationException("Not supported yet.");
    }

}
